#!/bin/bash

chip=t23

ENV_DIR=$(pwd)/../../../../../
SDK_DIR=$(pwd)/../../../
OSD_DIR=$(pwd)/../osd/
ISP_DIR=$(pwd)/../isp/
SYSTEM_DIR=$(pwd)/../init_deinit/
ENCODER_DIR=$(pwd)/../encoder/
AUDIO_DIR=$(pwd)/../audio/
TARGET_DIR=$(pwd)/bin/

source_env(){
	echo source env
	cd ${ENV_DIR}
	source build/${chip}/env_setup.sh
	cd -
}

make_sdk(){
	echo make sdk
	cd ${SDK_DIR}
	rm -rf build/
	mkdir build
	cd build
	cmake ..
	make -j
	cd ../test/sdk_test/makedir
}

touch_dir(){
	rm -rf bin/
	mkdir bin
	mkdir $(pwd)/bin/osd/
	mkdir $(pwd)/bin/encoder/
	mkdir $(pwd)/bin/audio/
	mkdir $(pwd)/bin/audio/res/
	mkdir $(pwd)/bin/isp/
	mkdir $(pwd)/bin/init_deinit/
}

make_osd(){
	echo make osd
	cd ${OSD_DIR}
	make clean
	make -j
	cp sample-Encoder-OSD ../makedir/bin/osd/
	cd -
}

make_encoder(){
	echo make encoder
	cd ${ENCODER_DIR}
	make clean
	make -j
	cp sample-Encoder-h264-jpeg-test ../makedir/bin/encoder/
	cp sample-Encoder-changeRes-test ../makedir/bin/encoder/
	cp sample-Encoder-changeRcParam-test ../makedir/bin/encoder/
	cd -
}

make_audio(){
	echo make audio
	cd ${AUDIO_DIR}
	make clean
	make -j
	cp sample-Ai ../makedir/bin/audio/
	cp sample-Ao ../makedir/bin/audio/
	cp sample-Ai-AEC ../makedir/bin/audio/
	cp ./res/libaudioProcess.so ../makedir/bin/audio/res/ 
	cp ./res/webrtc_profile.ini ../makedir/bin/audio/res/ 
	cp ./res/test_for_play.pcm ../makedir/bin/audio/res/ 
	#cp sample-Hs ../makedir/bin/audio/
	#cp sample-AEC-HS ../makedir/bin/audio/
	#cp sample-Ai-AEC-Ageing ../makedir/bin/audio/
	cd -
}

make_isp(){
	echo make isp
	cd ${ISP_DIR}
	make clean
	make -j
	cp sample-ISP ../makedir/bin/isp/
	cp sh/ -r ../makedir/bin/isp/
	cd -
}

make_system(){
	echo make system
	cd ${SYSTEM_DIR}
	make clean
	make -j
	cp sample-System-init-deinit ../makedir/bin/init_deinit/
	cd -
}

source_env
make_sdk
touch_dir
make_osd
make_encoder
make_audio
make_isp
make_system

cp run.sh ./bin/
cp ../other/* -rf ./bin/
